import axios from 'axios'
import { ElMessage } from 'element-plus'

// 模拟数据
const mockData = {
  habits: [
    {
      id: 1,
      name: '晨跑',
      description: '每天早上跑步5公里',
      streak: 5,
      checkedToday: false
    },
    {
      id: 2,
      name: '阅读',
      description: '每天阅读1小时',
      streak: 3,
      checkedToday: true
    },
    {
      id: 3,
      name: '冥想',
      description: '每天冥想15分钟',
      streak: 10,
      checkedToday: false
    }
  ],
  events: [
    {
      id: 1,
      title: '团队会议',
      date: new Date('2023-12-25'),
      time: '10:00',
      type: 'primary',
      description: '与团队讨论本周工作进展'
    },
    {
      id: 2,
      title: '项目演示',
      date: new Date('2023-12-26'),
      time: '14:30',
      type: 'danger',
      description: '向客户展示项目最新进展'
    },
    {
      id: 3,
      title: '健身',
      date: new Date('2023-12-25'),
      time: '18:00',
      type: 'success',
      description: '去健身房锻炼'
    }
  ]
}

// 开发环境使用模拟数据
const useMockData = true

// 创建axios实例
const service = axios.create({
  baseURL: 'http://localhost:8081', // 确保这里是正确的后端地址
  timeout: 5000
})

// 请求拦截器
service.interceptors.request.use(
  config => {
    // 可以在这里添加token等认证信息
    return config
  },
  error => {
    console.log(error)
    return Promise.reject(error)
  }
)

// 响应拦截器
service.interceptors.response.use(
  response => {
    return response
  },
  error => {
    console.log('err' + error)
    return Promise.reject(error)
  }
)

export default service 